<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			div{
				border:1px #000 solid
			}
			#d1{
				width:150px;
				height: 150px;
			}
			#d2{
				width:100px;
				height: 100px;
			}
			#d3{
				width:50px;
				height: 50px;
			}
		</style>
	</head>
	<body>
		<div id="d1">d1
			<div id="d2">d2
				<div id="d3">d3</div>
			</div>
		</div>
		<script type="text/javascript">
			//为网页中的所有div添加单机事件(事件监听),要求输出div的id属性值
			const divs=document.querySelectorAll("div")
			for (let i = 0; i < divs.length; i++) {
				divs[i].addEventListener("click",fun1,true)//捕获型
				divs[i].addEventListener("click",fun2,false)//冒泡型
			}
			function fun1(){
				console.log(`fun1:${event.currentTarget.id}`)
				//event.stopPropagation()
			}
			function fun2(){
				console.log(`fun2:${event.currentTarget.id}`)
				event.stopPropagation()//阻止事件传播
			}
		</script>
	</body>
</html>
